import com.aip.*;

public class sample 
{
    public static void main(String args[])
    {
    	System.out.println("operate\t\t\tlen\tpos\tsize");
        System.out.println("================================================:W");
        
        ByteCool bin = new ByteCool(0);
        
        byte i8 = 127;
        bin.WriteInt8(i8);
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","wI8",i8,bin.GetLength(),bin.GetPosition(),bin.GetSize());

        byte u8 = (byte)254;
        bin.WriteUint8(u8);
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","wU8",u8 ,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        short i16 = 32766;
        bin.WriteInt16(i16);
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","wI16",i16,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        short u16 = (short)65533;
        bin.WriteUint16(u16);
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","wU16",u16,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        int i32 = (int)2147483644;
        bin.WriteInt32(i32);
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","wI32",i32,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        int u32 = -2147483642;
        bin.WriteUint32(u32);
        System.out.printf("%s:%d\t%d\t%d\t%d\n","wU32",u32,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        //float f32 = (float)3.40282e+038;
        //float f32 = (float)-3.40282e+038;
        float f32 = (float)123.456;
        bin.WriteFloat32(f32);
        System.out.printf("%s:%f\t\t%d\t%d\t%d\n","wF32",f32,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        //double f64 = 1.79769e+308;
        //double f64 = -1.79769e+308;
        double f64 = 456.78901234;
        bin.WriteFloat64(f64);
        System.out.printf("%s:%f\t\t%d\t%d\t%d\n","wF64",f64,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.println("================================================:R");
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","rI8",bin.ReadInt8(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","rU8",bin.ReadUint8(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","rI16",bin.ReadInt16(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.printf("%s:%d\t\t\t%d\t%d\t%d\n","rU16",bin.ReadUint16(),bin.GetLength(),bin.GetPosition(),bin.GetSize());

        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","rI32",bin.ReadInt32(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.printf("%s:%d\t%d\t%d\t%d\n","rU32",bin.ReadUint32(),bin.GetLength(),bin.GetPosition(),bin.GetSize());

        System.out.printf("%s:%f\t\t%d\t%d\t%d\n","rF32",bin.ReadFloat32(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.printf("%s:%f\t\t%d\t%d\t%d\n","rF64",bin.ReadFloat64(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        System.out.println("================================================:abbr");
        System.out.printf("r:%d\n",bin.GetBytesReadable());
        System.out.printf("w:%d\n",bin.GetBytesWriteable());
        
        System.out.println("================================================:bin/str");
        
        ByteCool data = new ByteCool(3);
        data.WriteInt8((byte)11);
        data.WriteInt8((byte)12);
        data.WriteInt8((byte)13);
        
        byte[] bytes = new byte[]{101,102,103};
        
        bin.WriteBin(data);
        System.out.printf("%s:%d\t%d\t%d\t%d\n","wBin(len)",data.GetLength(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        ByteCool tmpA = bin.ReadBin(3);
        System.out.printf("%s:%s\t%d\t%d\t%d\n","rBin",tmpA.ReadInt8()+","+tmpA.ReadInt8()+","+tmpA.ReadInt8(),bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        bin.WriteBytes(bytes);
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","wBytes(len)",bytes.length,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        byte[] tmpB = bin.ReadBytes(bytes.length);
        System.out.printf("%s:%s\t%d\t%d\t%d\n","rBytes",tmpB[0]+","+tmpB[1]+","+tmpB[2],bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        String string = "hello";
        bin.WriteUTF8(string);
        System.out.printf("%s:%s\t\t%d\t%d\t%d\n","wString",string,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        System.out.printf("%s:%s\t\t%d\t%d\t%d\n","rString",bin.ReadUTF8(string.length()),bin.GetLength(),bin.GetPosition(),bin.GetSize());

        String stringB = " world !";
        bin.WriteLenUTF8(stringB);
        System.out.printf("%s:%s\t%d\t%d\t%d\n","wLenStr",stringB,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        System.out.printf("%s:%s\t%d\t%d\t%d\n","rLenStr",bin.ReadLenUTF8(),bin.GetLength(),bin.GetPosition(),bin.GetSize());

        bin.WriteLenBytes(bytes);
        byte[] tmpC = bin.ReadLenBytes();
        System.out.printf("%s:%d\t%d\t%d\t%d\n","wLenBytes(len)",bytes.length,bin.GetLength(),bin.GetPosition(),bin.GetSize());
        System.out.printf("%s:%s\t%d\t%d\t%d\n","rLenBytes",tmpC[0]+","+tmpC[1]+","+tmpC[2],bin.GetLength(),bin.GetPosition(),bin.GetSize());
        
        ByteCool clone = bin.Clone(false);
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","cloneF",clone.ReadInt8(),clone.GetLength(),clone.GetPosition(),clone.GetSize());
        
        ByteCool cloneB = bin.Clone(true);
        System.out.printf("%s:%d\t\t%d\t%d\t%d\n","cloneT",cloneB.ReadInt8(),cloneB.GetLength(),cloneB.GetPosition(),cloneB.GetSize());
        
        try{
            System.in.read();
        } catch(Exception e){}
    }
}